<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            height: 20px;
            width: 50px;
            margin-top: 10px;
            background: #333
        }
    </style>
</head>

<body>
    <main>
        <div data-sp="flase">1</div>
        <div data-sp="flase">2</div>
        <div data-sp="flase">3</div>
        <div data-sp="flase">4</div>
    </main>
    <button class="btn">提交</button>
</body>
<script>
    function siblings(elm) {
        var a = [];
        var p = elm.parentNode.children;
        for (var i = 0, pl = p.length; i < pl; i++) {
            if (p[i] !== elm) a.push(p[i]);
        }
        return a;
    }

    var divs = document.querySelectorAll("div")
    // console.log(divs)
    for (var i = 0; i < divs.length; i++) {
        // console.log(i)
        divs[i].addEventListener("click", function () {
            // console.log(siblings(this))
            var p = this.parentNode.children
            console.log(p)
            if (this.getAttribute("data-sp") == 'flase') {
                this.setAttribute("data-sp", "true")
                siblings(this)
                for (var a1 = 0; a1 < siblings(this).length; a1++) {
                    siblings(this)[a1].setAttribute("data-sp", "flase")
                }
            } else {
                this.setAttribute("data-sp", "flase")
            }
        })
    }
    var btn = document.querySelector(".btn")
    var ssss = btn.addEventListener("click", function () {
        for (var i = 0; i < divs.length; i++) {
            console.log(i)
            if (divs[i].getAttribute("data-sp") === "true") {
                var ss = divs[i].innerHTML
            }
        }
        console.log(ss)
        return ss
    })
    // console.log(ssss)
</script>

</html>